﻿using System.Collections.Generic;
using DataEntities;
using NUnit.Framework;
using Repositories.Repository;
using Repositories.UoW;

namespace TestRepositories
{
    [TestFixture]
    public class TestSectorsRepository : ITestRepository
    {
        private ISectorRepository _repository;
        private RepositoryFactory _repositoryFactory;
        private Sector _sector;

        [SetUp]
        public void SetUp()
        {
            SessionFactory.Init();
            SessionFactory.GetSession().Flush();
            _repositoryFactory = new RepositoryFactory();
            _repository = _repositoryFactory.GetSectorRepository();
        }

        [TearDown]
        public void CleanUp()
        {
        }

        [Test]
        public void TestGet()
        {
            Assert.AreEqual(1, _repository.Get(1).Id);
        }

        [Test]
        public void TestGetList()
        {
            Assert.AreEqual(36, _repository.GetList().Count);
        }

        [Test]
        public void TestInsert()
        {
            Assert.AreEqual(1, _repository.Insert(new Sector(1000,"test")));
            Assert.AreEqual(1, _repository.Insert(new Sector(1001,"test1")));
            Assert.AreEqual(1, _repository.Insert(new Sector(1002,"test2")));
        }

        [Test]
        public void TestUpdate()
        {
            _sector = _repository.Get(1);
            _sector.Info = "TestUpdated";
            Assert.AreEqual(1, _repository.Update(_sector));
        }

        [Test]
        [Ignore]
        public void TestDelete()
        {
            _sector = new Sector(2, "Советский");
            Assert.AreEqual(1, _repository.Delete(_sector));
        }

        [Test]
        public void TestEquals()
        {
            _sector = new Sector(2, "Советский");
            Assert.AreEqual(_sector, _repository.Get(2));
        }

        [Test]
        public void TestInsertList()
        {
            IList<Sector> list = new List<Sector>();
            list.Add(new Sector(1003, "InsertList test"));
            list.Add(new Sector(1004, "InsertList test1"));
            list.Add(new Sector(1005, "InsertList test2"));
            Assert.AreEqual(3, _repository.InsertList(list));
        }

        [Test]
        public void UpdateList()
        {
            IList<Sector> list = new List<Sector>();
            list.Add(_repository.Get(12));
            list.Add(_repository.Get(33));
            list.Add(_repository.Get(50));
            list.Add(_repository.Get(62));

            foreach (Sector item in list)
            {
                item.Info += "UpdatedList";
            }

            Assert.AreEqual(4, _repository.UpdateList(list));
        }

        [Test]
        [Ignore]
        public void TestDeleteList()
        {
            IList<Sector> list = new List<Sector>();
            list.Add(_repository.Get(12));
            list.Add(_repository.Get(33));
            list.Add(_repository.Get(50));
            list.Add(_repository.Get(62));
            Assert.AreEqual(4, _repository.DeleteList(list));
        }

        [Test]
        public void TestGetChildDogovorList()
        {
            Assert.AreEqual(11, _repository.Get(2).DogovorList.Count);
        }
    }
}